package org.casscommunity.sights.client.activity;

import org.casscommunity.sights.client.view.EditPlaceView;
import org.casscommunity.sights.client.view.EditPlaceView.Presenter;
import org.casscommunity.sights.shared.place.EditPlace;

import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.inject.Inject;
import com.google.inject.Singleton;

public class EditPlaceActivity extends AbstractActivity implements Presenter {

	private EditPlaceView view;
	private PlaceController placeController;
	
	public EditPlaceActivity(EditPlace place, EditPlaceView view, PlaceController placeController) {
		this.view = view;
		this.placeController = placeController;
	}
	
	@Override
	public void start(AcceptsOneWidget panel, EventBus eventBus) {
		view.setPresenter(this);
		panel.setWidget(view.asWidget());
	}

	@Override
	public void goTo(Place place) {
		placeController.goTo(place);
	}
	
	@Singleton
	public static class EditPlaceActivityFactory implements ActivityFactory<EditPlaceActivity, EditPlace> {
		@Inject EditPlaceView view;
		@Inject PlaceController placeController;
		public EditPlaceActivity createActivity(EditPlace place) {
			return new EditPlaceActivity(place, view, placeController);
		}
	}
	
}
